package com.beiming.libra.service.impl;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.beiming.libra.common.page.PageResult;
import com.beiming.libra.common.utils.HttpClientUtils;
import com.beiming.libra.domain.dto.tdhnet.requestdto.TdhnetRequestDTO;
import com.beiming.libra.domain.dto.tdhnet.requestdto.TdhnetWajjbxxRequestDTO;
import com.beiming.libra.domain.dto.tdhnet.responsedto.TdhnetResponseDTO;
import com.beiming.libra.domain.dto.tdhnet.responsedto.TdhnetResult;
import com.beiming.libra.service.TdhnetService;

import lombok.extern.slf4j.Slf4j;


/**
 * 庭审三公开小程序通达海取数
 * @author lenovo
 *
 */

@Service
@Slf4j
public class TdhnetServiceImpl implements TdhnetService {
	final static String HTTPURL = "http://221.226.175.76:7208/sfjk/ssfw_app/app/";
	final static String METHOD_KTGG = "ktgg";
	/**
	 * 个案基本信息列表
	 */
	final static String METHOD_WAJJBXX = "wajjbxx";
	final static String CID = "BM_TDH_PORTAL";

	public void wajjbxx(TdhnetWajjbxxRequestDTO dto) {
		Map<String, String> map = objToMap(dto);
		String result = HttpClientUtils.sendHttpPost(HTTPURL + METHOD_WAJJBXX, map);
	}
	private static Map<String, String> objToMap(Object obj) {  
        Map<String, String> map = new HashMap<String, String>();  
        Field[] fields = obj.getClass().getDeclaredFields();  
        for (int i = 0; i < fields.length; i++) {  
            String varName = fields[i].getName();  
            try {  
                boolean accessFlag = fields[i].isAccessible();  
                fields[i].setAccessible(true);  
                Object o = fields[i].get(obj);  
                if (o != null)  {
                	map.put(varName, o.toString());  
                }
                fields[i].setAccessible(accessFlag);  
            } catch (IllegalArgumentException ex) {  
                ex.printStackTrace();  
            } catch (IllegalAccessException ex) {  
                ex.printStackTrace();  
            }  
        }  
        return map;  
    }  
	
	public static void main(String[] args) {
		String httpUrl = "http://221.226.175.76:7208/sfjk/ssfw_app/app/ktgg";
		Map<String, String> maps = new HashMap<String,String>();
		maps.put("cid", "BM_TDH_PORTAL");
		maps.put("fydm", "320100");
		maps.put("postion", "1");
 		String result = HttpClientUtils.sendHttpPost(httpUrl, maps);
// 		TdhnetResult tdhnetResult = JSON.parseObject(result, TdhnetResult.class);
// 		int size = tdhnetResult.getData().size();
// 		System.err.println(size);
		System.err.println(result);
		
	}
	

	@Override
	public PageResult<TdhnetResponseDTO> ktgg (TdhnetRequestDTO t) {
		Map<String, String> maps = objToMap(t);
		maps.put("cid", CID);
 		String result = HttpClientUtils.sendHttpPost(HTTPURL, maps);
 		TdhnetResult tdhnetResult = JSON.parseObject(result, TdhnetResult.class);
		System.err.println(result);
		log.debug("result");
		return null;
	}
}
